{include file="header.html"}
<div id="main">
  {include file="menus.html"}
  <div id="rightCon" class="clearfix layui-body">
    <div class="scroller">
      <div class="layui-tab">
        <ul class="layui-tab-title">
          <li><a href="{url route='msg/index'}">{$lang.sendlog}</a></li>
          <li class="layui-this">{$lang.msgrecharge}</li>
          <li><a href="{url route='msg/user'}">{$lang.msguser}</a></li>
          <li><a href="{url route='msg/add'}">{$lang.msgadd}</a></li>
          <li><a href="{url route='msg/template'}">{$lang.msgtemplate}</a></li>
          <li><a href="{url route='msg/send'}">{$lang.sendtest}</a></li>
        </ul>
      </div>
      <div class="search-form clearfix">
        <form method="get" id="formSearch">
        <div class="webkit-box box-align-center">
          <input type="hidden" name="r" value="msg/recharge" />
          {$lang.msguser}
          <input class="queryInput" type="text" name="username" value="{$smarty.get.username|escape}" />
          {$lang.phone_mob}
          <input class="queryInput" type="text" name="phone_mob" value="{$smarty.get.phone_mob|escape}" />
          <input type="submit" class="layui-btn layui-bg-blue layui-btn-sm block width7" value="{$lang.query}" />
          <!--{if $filtered}-->
          <a class="layui-btn layui-btn-primary layui-btn-sm box-align-center" href="{url route='msg/recharge'}">{$lang.cancel_query}</a>
          <!--{/if}-->
          </div>
        </form>
      </div>
      <div class="tablegrid">
        <table class="layui-hide" id="tablegrid" lay-filter="tablegrid"></table>
      </div>
      {include file="version.html"}
    </div>
  </div>
</div>
<script type="text/html" id="toolbar">
	<div class="layui-btn-container">
    <button class="layui-btn layui-bg-blue" lay-event="batdel"><i class="layui-icon layui-icon-close"></i>批量删除</button>
	</div>
</script>

<script>
  layui.use('table', function () {
    var table = layui.table;

    table.render({
      elem: '#tablegrid'
      //,skin: 'line'
      , url: url(['msg/recharge', $("#formSearch").serializeJson()])
      , toolbar: '#toolbar'
      , defaultToolbar: ['filter', /*'exports',*/ 'print']
      , title: '短信充值记录'
      //, size: 'lg'
      , cols: [[
        { type: 'checkbox', fixed: 'left' }
        , { field: 'id', title: 'ID', width: 70, fixed: 'left', unresize: true, sort: true }
        , {
          field: 'username', title: '短信用户', width: 120, sort: true, templet: function (res) {
            return (res.userid && res.username) ? res.username : lang.system;
          }
        }
        , { field: 'phone_mob', title: '手机号码', width: 200, sort: true }
        , {
          field: 'quantity', title: '充值数量', width: 170, sort: true, templet: function (res) {
            return res.quantity > 0 ? '<em class="green">+' + res.quantity + '</em>' : '<em class="red">' + res.quantity + '</em>';
          }
        }
        , { field: 'add_time', title: '充值时间', width: 200, sort: true }
        , { field: 'message', title: '备注', width: 395 }
        , {
          fixed: 'right', field: 'status', title: '状态', width: 110, sort: true, templet: function (res) {
            return res.status == 1 ? '<em class="green">成功</em>' : '<em>失败</em>';
          }
        }
      ]]
      , page: {
        theme: 'blue'
      }
    });

    //监听头工具栏事件
    table.on('toolbar(tablegrid)', function (obj) {
      var checkStatus = table.checkStatus(obj.config.id);
      if (checkStatus.data.length <= 0) {
        return false;
      }
      var items = new Array();
      $.each(checkStatus.data, function (i, item) {
        items.push(item.id);
      });
      if (obj.event === 'batdel') {
        var btnObj = $('[lay-event="' + obj.event + '"]');
        btnObj.attr('confirm', '删除后将不能恢复，确认删除这 ' + items.length + ' 项吗？');
        ajaxRequest(btnObj, url(['msg/delete', { id: items.join(',') }]), function () {
          table.reload('tablegrid');
        });
      }
    });
  });
</script>
{include file="footer.html"}